{template 'common/header'}
<script>
    $(function(){
        $(".del_member").click(function(){
            var member_id = $(this).attr("member_id");
            if(member_id > 0){
                if(confirm("是否确定删除客户？")){
                    var url = "{php echo $this->createWebUrl('members',array('op' => 'del_member'))}";
                    $.ajax({
                        type : "post",
                        url : url,
                        data : {'member_id' : member_id},
                        success : function(data){
                            if(data == 111){
                                alert('操作成功！');
                                location.reload();
                            }else{
//                                alert(data);
                            }
                        }
                    });
                }
            }
        });
        $(".find").click(function(){
            var key = $("#key").val();
            var region_id = $("#region_id").val();
            var remark = $("#remark").val();
            location.href = "{php echo $this->createWebUrl('members',array('op' => 'index'))}&key="+key+"&region_id="+region_id+"&remark="+remark;
        });
        $(".export_data").click(function(){
            var key = $("#key").val();
            var region_id = $("#region_id").val();
            var remark = $("#remark").val();
            location.href = "{php echo $this->createWebUrl('members',array('op' => 'export'))}&key="+key+"&region_id="+region_id+"&remark="+remark;
        });
        $(".short-name").on('blur',function(){
            var short_name = $(this).val();
            var member_id = $(this).attr('member-id');
            var url = "{php echo $this->createWebUrl('members',array('op' =>'change_short_name'))}";
            $.ajax({
                type : "post",
                url : url,
                data : {'short_name' : short_name, 'member_id' : member_id},
                success : function(data){
                    if(data == 111){
                        location.reload();
                    }else{
                        alert(data);
                    }
                }
            });
        });
        $(".list_order").blur(function(){
            var list_order = $(this).val();
            var member_id = $(this).attr('member_id');
            var url = "{php echo $this->createWebUrl('members',array('op' =>'change_list'))}";
            $.ajax({
                type : "post",
                url : url,
                data : {'list_order' : list_order, 'member_id' : member_id},
                success : function(data){
                    if(data == 111){
                        location.reload();
                    }else{
//                        alert(data);
                    }
                }
            });
        });
    });

</script>
<ul class="nav nav-tabs">
    <li class="active" ><a href="{php echo $this->createWebUrl('members', array('op'=>'index'))}">客户列表</a></li>
    <li ><a href="{php echo $this->createWebUrl('members', array('op'=>'add'))}">新增客户</a></li>
</ul>
<div>

    <div class="panel panel-primary">
        <div class="panel-body">
            <div class="row">
                <div class="col-xs-3">
                    <input type="text" placeholder="客户名/助记码/电话" id="key" class="form-control" value="{$key_word}" />
                </div>
                <div class="col-xs-3">
                    <select class="form-control" id="region_id">
                        <option value="0">全部地区</option>
                        {loop $regions $r}
                        <option value="{$r['id']}" {if $r['id'] == $region_id} selected="selected" {/if}>{$r['name']}</option>
                        {/loop}
                    </select>
                </div>
                <div class="col-xs-3">
                    <input type="text" placeholder="备注" class="form-control" id="remark" value="{$remark}" />
                </div>
                <div class="col-xs-3">
                    <button class="btn btn-primary find">搜索</button>
                    <button class="btn btn-info export_data">导出</button>
                </div>
            </div>
        </div>
    </div>

    <table class="table">
        <tr>
            <th>客户</th>
            <th>电话</th>
            <th>所属区域</th>
            <th>助记码</th>
            <th>排序</th>
            <th>热度</th>
            <th>备注</th>
            <th>操作</th>
        </tr>
        {loop $list $l}
        <tr>
            <td>{$l['name']}</td>
            <td>{$l['phone']}</td>
            <td>{$l['region']}</td>
            <td>
                <input type="text" value="{$l['short_name']}" member-id="{$l['id']}" class="form-control short-name" style="width: 100px;"/>

            </td>
            <td>
                <input type="text" member_id="{$l['id']}" value="{$l['list_order']}" class="form-control list_order" style="width: 100px;" />
            </td>
            <td>
                <input type="text" member_id="{$l['id']}" value="{$l['click_numbers']}" class="form-control" style="width: 100px;" readonly="readonly"/>
            </td>
            <td>{$l['remark']}</td>
            <td>
                <a href="{php echo $this->createWebUrl('members',array('op' => 'add', 'id' => $l['id']))}">
                    <button class="btn btn-primary">修改</button>
                </a>

                <button class="btn btn-danger del_member" member_id="{$l['id']}">删除</button>
                <a href="{php echo $this->createWebUrl('members',array('op' => 'goods','member_id' => $l['id']))}">
                    <button class="btn btn-default">常用商品</button>
                </a>
                <a href="{php echo $this->createWebUrl('members',array('op' => 'members','member_id' => $l['id']))}">
                    <button class="btn btn-default">常用寄货人</button>
                </a>
            </td>
        </tr>
        {/loop}
    </table>
    {$pager}
</div>



{template 'common/footer'}